<template>
  <div v-loading="loading">
    <instance-search v-model="params" :show-finished="false" :keyword-text="$t('webAuto.nodeName')"/>
    <el-table :data="dataList" :header-cell-style="{ background: '#e8e8e8' }" style="width: 100%; margin: 20px 0"
              @row-click="showProcess">
      <el-table-column fixed prop="processDefName" :label="$t('webAuto.ProcessType')" show-overflow-tooltip>
        <template v-slot="scope">
          <el-tag size="small" type="success" v-if="scope.row.superInstanceId !== scope.row.instanceId">{{$t('webAuto.son')}}</el-tag>
          <span style="margin-left: 5px">{{ scope.row.processDefName }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="businessKey" :label="$t('webAuto.RequestNo')" min-width="110px"></el-table-column>
      <el-table-column prop="instanceId" :label="$t('webAuto.LCInstanceNumber')" min-width="130px"></el-table-column>
      <el-table-column prop="formAbstracts" show-overflow-tooltip :label="$t('webAuto.summaryInformation')" min-width="130px">
        <template v-slot="scope">
          <form-abstracts :value="scope.row.formAbstracts"/>
        </template>
      </el-table-column>
      <el-table-column prop="owner" show-overflow-tooltip :label="$t('webAuto.promoter')" min-width="100px">
        <template v-slot="scope">
          <w-avatar :size="35" :name="scope.row.owner.name" :src="scope.row.owner.avatar" v-if="scope.row.owner"/>
        </template>
      </el-table-column>
      <el-table-column show-overflow-tooltip prop="createTime" :label="$t('webAuto.SubmissionTime')" min-width="120px"></el-table-column>
      <el-table-column show-overflow-tooltip prop="taskName" :label="$t('webAuto.currentNode')">
        <template v-slot="scope">{{ $t(scope.row.taskName) }}</template>
      </el-table-column>
      <el-table-column show-overflow-tooltip prop="taskCreateTime" :label="$t('webAuto.TaskArrivalTime')"
                       min-width="120px"></el-table-column>
      <el-table-column prop="status" :label="$t('webAuto.ApprovalStatus')">
        <template v-slot="scope">
          <el-tag>{{$t('webAuto.WaitHandle')}}</el-tag>
        </template>
      </el-table-column>
      <!--      <el-table-column fixed="right" label="操作" min-width="90">
          <template v-slot="scope">
            <el-button type="text">立即处理</el-button>
          </template>
        </el-table-column>-->
    </el-table>
    <div style="text-align: right">
      <el-pagination hide-on-single-page background layout="prev, pager, next" :total="total"
                     :page-size="params.pageSize" v-model:current-page="params.pageNo"></el-pagination>
    </div>
    <el-dialog  :title="$t('webAuto.ApprovalDetails')" v-model="processVisible" closeFree  style="height: auto;min-height:100%;;width: 100%;margin:0!important;" :close-on-click-modal="false"
      :close-on-press-escape="false"> 
      <!-- :size="isMobile ? '100%' : '500px'" direction="rtl" -->
      <instance-preview v-if="processVisible" :node-id="selectInstance.nodeId" :instance-id="selectInstance.instanceId"
                        @handler-after="handlerAfter"></instance-preview>
    </el-dialog>
  </div>
</template>

<script>
import taskApi from '@/api/processTask'
import InstancePreview from '../approval/ProcessInstancePreview2.vue'
import FormAbstracts from "./FormAbstracts.vue";
import InstanceSearch from "../../common/InstanceSearch.vue";

export default {
  name: 'UnFinished',
  components: {InstancePreview, FormAbstracts, InstanceSearch},
  data() {
    return {
      total: 0,
      params: {
        pageSize: 10,
        pageNo: 1,
        code: '',
        startTimes: []
      },
      loading: false,
      selectInstance: null,
      processVisible: false,
      formList: [],
      dataList: [],
    }
  },
  computed: {
    isMobile() {
      return window.screen.width < 450
    },
  },
  mounted() {
    this.getTodoList()
  },
  methods: {
    getTodoList() {
      this.loading = true
      const params = Object.assign({}, this.params)
      params.startTimes = String(params.startTimes)
      taskApi.getUserTodoList(params).then((rsp) => {
        this.loading = false
        this.total = rsp.data.total
        this.dataList = rsp.data.records
      }).catch((e) => {
        this.loading = false
      })
    },
    showProcess(row) {
      this.processVisible = true
      this.selectInstance = row
    },
    handlerAfter() {
      this.processVisible = false
      this.getTodoList()
    },
  },
  watch: {
    params: {
      deep: true,
      handler() {
        this.getTodoList()
      },
    },
  },
}
</script>

<style scoped></style>
